from django.contrib import admin
from .models import Review

@admin.register(Review)
class ReviewAdmin(admin.ModelAdmin):
    list_display = (
        'order_id',
        'chef_name',
        'customer_name',
        'overall_rating',
        'created_at'
    )
    list_filter = ('overall_rating', 'is_public')
    readonly_fields = ('created_at', 'updated_at')
    fieldsets = (
        ('关联信息', {
            'fields': (
                'order',
                'chef',
                'customer'
            )
        }),
        ('评分', {
            'fields': (
                'food_quality',
                'service',
                'cleanliness',
                'overall_rating'
            )
        }),
        ('内容', {
            'fields': (
                'comment',
                'is_public'
            )
        }),
        ('时间戳', {
            'fields': (
                'created_at',
                'updated_at'
            )
        })
    )

    def order_id(self, obj):
        return f"Order #{obj.order.id}"
    order_id.short_description = "订单"

    def chef_name(self, obj):
        return obj.chef.user.get_full_name()
    chef_name.short_description = "厨师"

    def customer_name(self, obj):
        return obj.customer.get_full_name()
    customer_name.short_description = "顾客"